{extend name="wap/default_new/base" /}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/foundation.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/common-v4.4.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/normalize.css">
<link rel="stylesheet" type="text/css" href="__TEMP__/{$style}/public/css/dis-v4.4.css">
<style>
.arrow {position: absolute; right:30px;top: 48%; }
.extract { margin: 44px 0px 0px 0px;background:#FFF;padding:20px 15px;}
input {width: 100%;height: 23px;}
.extract-monynumber .columns {padding: 10px;background:#fff;}
.tip-text{color:#FF4040;margin-top:45px;padding:10px;margin-bottom:0;}
.button.red {padding: 8px 0px;line-height: 1.33;border-radius: 3px;background: #FF4040;margin:auto;border-color: #ec522c;width:95%;}
.btn_all{width:100%;text-align:center;}
.horn-text{background:none;color:#000000;border:none;}
.extract-number .number {font-size: 16px; }
.side-nav li{ position: relative;}
</style>
{/block} 

{block name="main"}
<section class="head">
	<a class="head_back" href="javascript:window.history.go(-1);"><i class="icon-back"></i></a>
	<div class="head-title" >{:lang('apply_for_cash')}</div>
</section>
<div data-alert class="alert-box alert" id="errerMsg" style="display: none;"><a href="#" class="close">&times;</a></div>
<div class="panel extract">
	<div class="commision-total">
		<span class="span-title" style="color:#000000;">{:lang('member_cash_available')}：</span>
		<span class="number" style="font-size:18px;color:#FF4040;"id="Amount">¥{$account}</span>
	</div>
</div>

<div class="panel extract-account" style="border:0px;">
	<ul class="side-nav" >
		{if condition="count($account_list) eq 0"}
		<li>
			<a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;">
				<span>{:lang('please_add_a_cash_account')} <br></span>
				<i class="arrow"></i>
			</a>
		</li>
		{else/}
		<li>
		{volist name="account_list" id="vo"}
			{if condition="$vo.account_type == 1"}
			<a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;">
				<span>{$vo.branch_bank_name}<br>{$vo.account_number}</span>
				<i class="arrow"></i>
			</a>
			
			{elseif condition="$vo.account_type == 2" /}
			<a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;">
				<span>{$vo.account_type_name}</span>
				<i class="arrow" style="top:36%;"></i>
			</a>
			{elseif condition="$vo.account_type == 3" /}
			<a href="{:__URL('APP_MAIN/member/accountlist?shop_id='.$shop_id)}" style="padding:6px 15px;">
				<span>{$vo.account_type_name}<br>{$vo.account_number}</span>
				<i class="arrow"></i>
			</a>
			{/if}
			<input type="hidden" value="{$vo.id}" id="bank_account_id"/>
		{/volist}
		</li>
		{/if}
	</ul>
</div>

<div class="row extract-monynumber">
	<div class="large-12 columns">
		<input type="text" class="" style="border:0px;" id="money" placeholder="{:lang('member_enter_amount')}">
	</div>
	{if condition="$cash neq '' && $poundage neq ''"}
	<div class="tip-text">{:lang('member_minimum_withdrawal')}<span id="MinaAmountCash">{$cash}</span>{:lang('element')}，{:lang('member_must_serve')}<span id="IntTimes">{$poundage}</span>{:lang('member_integral_multiple')}</div>
	{else/}
	<div class="tip-text">{:lang('member_minimum_withdrawal')}<span id="MinaAmountCash">0</span>{:lang('element')} ，{:lang('member_must_serve')}<span id="IntTimes">1</span>{:lang('member_integral_multiple')}</div>
	{/if}
</div>

<div class="btn_all">
	<a href="javascript:;" onclick="btnSave()" class="button red">{:lang('member_apply_immediately')}</a>
	{if condition="$withdraw_message neq ''"}
	<div class="horn-text"> {:lang('member_notes')}:{$withdraw_message}</div>
	{/if}
</div>

<input type="hidden" value="{$shop_id}" id="id"/>
{/block}
{block name="bottom"}{/block}
{block name="javascript"}
<script type="text/javascript">
function btnSave(){
	var shop_id = $("#id").val();
	var bank_account_id = $("#bank_account_id").val();
	var cash = $.trim($("#money").val());
	var MaxCashAmount = $.trim($("#Amount").text());
	var MinaAmountCash = $.trim($("#MinaAmountCash").text());
	var IntTimes = $.trim($("#IntTimes").html());
	MaxCashAmount = MaxCashAmount.substr(1);
	if(bank_account_id == null || bank_account_id == ""){
		showBox("{:lang('no_withdrawals_account_was_added')}","warning");
		return;
	}
	var reg = /^\+?[1-9][0-9]*$/;
	if (reg.test(cash)) {
		cash = Number(cash);
		MaxCashAmount = Number(MaxCashAmount);
		MinaAmountCash = Number(MinaAmountCash);
		if (cash > 0) {
			if (cash <= MaxCashAmount) {
				if (cash >= MinaAmountCash) {
					if (cash % parseInt(IntTimes) == 0) {
						$.ajax({
							type:"post",
							url: "{:__URL('APP_MAIN/member/towithdraw')}",
							data: { "bank_account_id": bank_account_id, "cash": cash},
							success: function (res) {
								if (res['code'] >0) {
									showBox("{:lang('member_submitted_for_review')}...","success", __URL("APP_MAIN/member/balancewater?shop_id="+shop_id));
								} else {
									showBox(res.outmessage,"error");
								}
							}
						});
					} else {
						showBox("{:lang('member_withdrawals_must_be')}" + IntTimes + "{:lang('member_integral_multiple')}","warning");
						return false;
					}
				} else {
					showBox("{:lang('member_withdrawals_must_greater')}" + MinaAmountCash,"warning");
					return false;
				}
			} else {
				showBox("{:lang('member_maximum_amount')}" + MaxCashAmount,"warning");
				return false;
			}
		} else {
			showBox("{:lang('member_not_present')}","warning");
			return false;
		}
	} else {
		showBox("{:lang('member_amount_not_legal')}","warning");
		return false;
	}
}
</script>
{/block}